package borge.web.teamspirit.client.page.team.widgets;

import borge.web.teamspirit.client.SessionData;
import borge.web.teamspirit.client.TeamSpirit;
import borge.web.teamspirit.client.TeamSpiritConstants;
import borge.web.teamspirit.client.data.Serie;
import borge.web.teamspirit.client.data.TeamPlayer;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler.WidgetEventType;
import borge.web.teamspirit.client.page.shared.widgets.CreateDataWidget;
import borge.web.teamspirit.client.page.shared.widgets.InputWrapper;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

public class CreateSerieWidget extends CreateDataWidget implements ClickHandler {

    private Serie iSerie;
    
    public CreateSerieWidget(WidgetEventHandler aEventHandler){
        super(aEventHandler);
    
    
        iPanel.add(iTable);
        initWidget(iPanel);
    }
    
    private void createDataTable(){
        TeamSpiritConstants lsc = TeamSpirit.getConstants();
        int row = 0;
        final int maxLength = 10;
        
        if(iSerie == null)
        	iSerie = new Serie();
        
//        addTableRow(row++, new InputWrapper(lsc.season(), createTextBox(aSerie.getSeason(), maxLength), true));
//        addTableRow(row++, new InputWrapper(lsc.division(), createTextBox(aSerie.getDivision(), maxLength), true));
//        //addTableRow(row++, new InputWrapper(lsc.start_date(), createDatePicker(aSerie.getStartDate()), true));
//        addTableRow(row++, new InputWrapper(lsc.start_date(), createDateBox(aSerie.getStartDate()), true));
//        addTableRow(row++, new InputWrapper(lsc.end_date(), createDateBox(aSerie.getEndDate()), true));
//        
//        addTableRow(row++, new InputWrapper(lsc.placement(), createTextBox(aSerie.getPlacement(), maxLength), false));
//        addArrayTableRow(row++, new InputWrapper(lsc.type(), SerieEnums.Type.values(), null, getSelectedType(aSerie.getType()), true));
//        addArrayTableRow(row++, new InputWrapper(lsc.status(), SerieEnums.Status.values(), null, getSelectedStatus(aSerie.getStatus()), true));
//        
        // We want to listen to ListBox events for Status, so we can enable/disable Placement
        // textbox depending on serie status
        
        addButton(row, 0, this);	
    }
    
    
    @SuppressWarnings("unchecked")
    public Serie getDataObject(){
        return iSerie;
    }
    
    public void onClick(ClickEvent aEvent){
        
        postEvent(WidgetEventType.SERIE_CREATED);
        
    }

    @Override
	public void updateData() {
		
		iSerie = (Serie)SessionData.sEditObject;
		SessionData.sEditObject = null;
		createDataTable();
	}
    
}
